<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>健康医疗</title>
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>
        <link rel="shortcut icon" href="../img/favicon.ico"/>
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../element-ui/index.css">
        <link rel="stylesheet" href="../css/style.css">
        <link rel="stylesheet" href="../css/font-awesome/css/font-awesome.min.css">
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>检查项管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item>首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>检查项管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input v-model="queryString" placeholder="会员id/预订类型/预订状态" style="width: 200px;"
                                  class="filter-item" @keyup.enter.native="handleCurrentChange(1)" clearable>
                        </el-input>
                        <el-button @click="handleCurrentChange(1)" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="member_id" label="会员id" align="center"></el-table-column>
                        <el-table-column prop="orderDate" label="预订日期" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预订类型" align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="预订状态" align="center"></el-table-column>
                        <el-table-column prop="setmeal_id" label="套餐id" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row.id)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination class="pagiantion"
                                       :current-page="pageNow"
                                       :page-size="pageSize"
                                       :total="total"
                                       layout="total, prev, pager, next, jumper"
                                       @current-change="handleCurrentChange">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹出层 -->
                    <div class="add-form">
                        <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                            <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                                     label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="会员id" prop="member_id">
                                            <el-input v-model="formData.member_id"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="预订日期" prop="orderDate">
                                            <el-input v-model="formData.orderDate"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="预订类型">
                                            <el-select v-model="formData.orderType">
                                                <el-option label="电话预约" value="1"></el-option>
                                                <el-option label="自助预约" value="2"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="预订状态">
                                            <el-select v-model="formData.orderStatus">
                                            <el-option label="已到诊" value="1"></el-option>
                                            <el-option label="未到诊" value="2"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="套餐名称">
                                            <el-input v-model="formData.setmeal_id" type="textarea"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹出层 -->
                    <div class="add-form">
                        <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit">
                            <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                                     label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="会员id" prop="member_id">
                                            <el-input v-model="formData.member_id"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="预订日期" prop="orderDate">
                                            <el-input v-model="formData.orderDate"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="预订类型">
                                            <el-select v-model="formData.borderType">
                                                <el-option label="电话预约" value="1"></el-option>
                                                <el-option label="自助预约" value="2"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="预订状态">
                                            <el-select v-model="formData.orderStatus">
                                                <el-option label="已到诊" value="1"></el-option>
                                                <el-option label="未到诊" value="2"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="套餐名称">
                                            <el-input v-model="formData.name" type="textarea"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../js/axios.min.js"></script>
    <script src="../element-ui/index.js"></script>
    <script type="text/javascript" src="../js/jquery-3.5.1.js"></script>
    <script>
        var vue = new Vue({
            el: '#app',
            data: {
                pageNow: 1,//当前页码
                pageSize: 8,//每页显示的记录数
                total: 0,//总记录数
                queryString: "",//查询条件
                dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                dialogFormVisible: false,//增加表单是否可见
                dialogFormVisible4Edit: false,//编辑表单是否可见
                rules: {//校验规则
                    code: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                    name: [{required: true, message: '项目名称为必填项', trigger: 'blur'}]
                }
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();
            },
            methods: {
                //编辑
                handleEdit() {
                    this.$refs["dataEditForm"].validate((valid) => {
                        //表单校验通过
                        if (valid) {
                            //打开全屏遮罩
                            var fullscreenLoading = this.$loading();

                            //提交
                            axios.post('../order/update', this.formData)
                                .then(res => {
                                    if (res.data.flag) {
                                        this.$message.success(res.data.msg);
                                        //关闭编辑窗口
                                        this.dialogFormVisible4Edit = false;
                                        //刷新列表
                                        this.findPage();
                                    } else {
                                        this.$message.warning(res.data.msg);
                                    }

                                    //关闭全屏遮罩
                                    fullscreenLoading.close();
                                })
                                .catch(error => {
                                    this.$message.error("请求出错：" + error);
                                    //关闭全屏遮罩
                                    fullscreenLoading.close();
                                });
                        }
                    });
                },
                //添加
                handleAdd() {
                    this.$refs["dataAddForm"].validate((valid) => {
                        //表单校验通过
                        if (valid) {
                            //打开全屏遮罩
                            var fullscreenLoading = this.$loading();

                            //提交添加
                            axios.post('../order/add', this.formData)
                                .then(res => {
                                    if (res.data.flag) {
                                        this.$message.success(res.data.msg);
                                        //关闭新增窗口
                                        this.dialogFormVisible = false;
                                        //刷新列表
                                        this.findPage();
                                    } else {
                                        this.$message.warning(res.data.msg);
                                    }

                                    //关闭全屏遮罩
                                    fullscreenLoading.close();
                                })
                                .catch(error => {
                                    this.$message.error("请求出错：" + error);
                                    //关闭全屏遮罩
                                    fullscreenLoading.close();
                                });
                        }
                    });
                },
                //分页查询
                findPage() {
                    //打开全屏遮罩
                    var fullscreenLoading = this.$loading();

                    var url = "../order/findPage/" + this.pageNow + "/" + this.pageSize
                        + "?" + "query=" + this.queryString;
                    axios.get(url)
                        .then(res => {
                            if (res.data.flag) {
                                // 分页的结果
                                this.dataList = res.data.data.rows;
                                // 总记录
                                this.total = res.data.data.total;
                            } else {
                                this.$message.warning(res.data.msg);
                            }

                            //关闭全屏遮罩
                            fullscreenLoading.close();
                        })
                        .catch(error => {
                            this.$message.error("请求出错：" + error);
                            //关闭全屏遮罩
                            fullscreenLoading.close();
                        });
                },
                // 重置表单
                resetForm() {
                    // 清空表单内容
                    this.formData = {};
                },
                // 弹出添加窗口
                handleCreate() {
                    // 弹出新增窗口
                    this.dialogFormVisible = true;
                    // 重置表单
                    this.resetForm();

                },
                // 弹出编辑窗口
                handleUpdate(id) {
                    //打开全屏遮罩
                    var fullscreenLoading = this.$loading();
                    //重置表单
                    this.resetForm();

                    //通过id查询检查项
                    axios.get('../order/findById/' + id)
                        .then(res => {
                            if (res.data.flag) {
                                //成功则绑定到formData
                                this.formData = res.data.data;
                                //弹出编辑窗口
                                this.dialogFormVisible4Edit = true;
                            } else {
                                this.$message.warning(res.data.msg);
                            }

                            //关闭全屏遮罩
                            fullscreenLoading.close();
                        })
                        .catch(error => {
                            this.$message.error("请求出错：" + error);
                            //关闭全屏遮罩
                            fullscreenLoading.close();
                        });
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pageNow = currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(id) {
                    this.$confirm('此操作将【永久删除】该检查项, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //打开全屏遮罩
                        var fullscreenLoading = this.$loading();

                        // 提交删除
                        axios.delete("../order/deleteById/" + id)
                            .then(res => {
                                if (res.data.flag) {
                                    this.$message.success(res.data.msg);
                                    //刷新列表
                                    this.findPage();
                                } else {
                                    this.$message.warning(res.data.msg);
                                }

                                //关闭全屏遮罩
                                fullscreenLoading.close();
                            })
                            .catch(error => {
                                this.$message.error("请求出错：" + error);
                                //关闭全屏遮罩
                                fullscreenLoading.close();
                            });
                    }).catch(() => {
                    });
                }
            }
        })
    </script>
</html>